package com.antu.first.service.impl;

import com.antu.first.bean.Room;
import com.antu.first.bean.RoomType;
import com.antu.first.dao.RoomDao;
import com.antu.first.dao.RoomTypeDao;
import com.antu.first.service.RoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/3/5.
 */
@Service("roomTypeService")
public class RoomTypeServiceImpl  implements RoomTypeService {


    @Autowired
    private RoomTypeDao roomTypeDao;
    boolean flag;
    Map<String, Object> map;
    List<RoomType>list=new ArrayList();
    @Override
    public Map<String, Object> queryRoomTypeByHid(int hId) {
        map=new HashMap<String,Object>();
        list= roomTypeDao.queryRoomTypeByHid(hId);
        map.put("roomTypes",list);
        return map;
    }

    @Override
    public Map<String, Object> updateRoomTypeByRoomTypeId(RoomType roomType) {
        map=new HashMap<String,Object>();
        if(roomType.getRtId()!=0&&roomType.getRtName()!=null&&roomType.getRtDesc()!=null&&roomType.getHotel()!=null){
            int i=roomTypeDao.updateRoomTypeByRoomTypeId(roomType);
            if(i>0){
                map.put("errMsg","修改操作成功");
                map.put("success",true);
            }
        }else{
            map.put("errMsg","修改操作失败，核对数据是否完整");
            map.put("success",false);
    }
        return map;
    }

    @Override
    public Map<String, Object> addRoomType(RoomType roomType) {
        if(roomType.getRtName()!=null&&roomType.getRtDesc()!=null&&roomType.getHotel()!=null){
            map=new HashMap<String,Object>();
            int i=roomTypeDao.addRoomType(roomType);
            if(i>0){
                map.put("success",true);
            }else{
                map.put("errMsg","添加操作失败，核对数据是否完整");
                map.put("success",true);
            }
        }else{
            map.put("errMsg","添加操作失败，核对数据是否完整");
            map.put("success",true);
        }
        return map;
    }

    @Override
    public Map<String, Object> deleteRoomType(RoomType roomType) {
        map=new HashMap<String,Object>();
        if (roomType.getRtId()!=0&&roomType.getHotel()!=null){
            int i=roomTypeDao.deleteRoomTypeById(roomType);
            if (i>0){
                map.put("success",true);
            }else{
                map.put("errMsg","删除操作失败，必须先删除对应的房间");
                map.put("success",false);
            }
        }else {
            map.put("errMsg","删除操作失败，必须先删除对应的房间");
            map.put("success",false);
        }
        return map;
    }
}
